
 def denormalize_tables
        row_counter = 0 
        root_tables = get_root_tables("denorm_config.csv")
        if root_tables.size < 2
              puts "Denormalization required atleast two tables"
        else
            denormalized_table_name = root_tables.join('_')
            new_connection = create_new_connection
            root_tables.each do |table_name|
                  create_structure_csv_file(table_name,new_connection)
                  FasterCSV.foreach("#{table_name}_structure.csv") do |row|
                        row_counter = row_counter + 1
                        for field_counter in 1..row.length-1
                              column_struc = get_the_col_specs(row[field_counter],table_name)
                              if row_counter == 1
                                  new_connection.query("CREATE TABLE #{denormalized_table_name} (#{row[0]} #{row[1]})")
                              else
                                  new_connection.query("ALTER TABLE #{denormalized_table_name} ADD `#{row[0]}` #{row[1]}")
                              end	
                        end
                  end
            end		
        end	
 end
 
 
 def create_denormalization_config_file
        first_norm_file = File.new("denorm_config.csv","w")
        first_norm_file.write("root table,")
        first_norm_file.write("\n")	
        first_norm_file.write("comments,")
        first_norm_file.write("for adding more child tables copy above two child table records and provide desired values.")
        first_norm_file.close 
 end 


